﻿/***********************************************************************/
/*                         Coding by C@T                                 */
/***********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Threading;


public partial class Pages_Register : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 0;
        txtFullName.Focus();
    }

    protected void Save()
    {
        HttpCookie register = new HttpCookie("Register");
        register.Values["Fullname"] = txtFullName.Text;
        register.Values["UserName"] = txtUser.Text;
        register.Values["Password"] = txtPass.Text;
        if (rdbMale.Checked)
        {
            register.Values["Gender"] = "Male";
        }
        else
        {
            register.Values["Gender"] = "Female";
        }
        register.Values["Email"] = txtEmail.Text;
        //DateTime dtExpiry = new DateTime(2012, 10, 9);
        //register.Expires = dtExpiry;
        Response.Cookies.Add(register);

        //Lưu cookies tạm thời
        //Response.Cookies["Register"]["UserName"] = txtUser.Text;
        //Response.Cookies["Register"]["Password"] = txtPass.Text;
    }

    protected void validation(bool valid)
    {
        if (valid == false)
        {
            CustomValidator1.IsValid = valid;            
            Birthdate.Focus();
        }
        else
        {
            this.Save();
            lbStatus.Text = "Thank you! You successfully registered";
            MultiView1.ActiveViewIndex = 1;
            btOk.Focus();
        }

    }

    protected void btReset_Click(object sender, EventArgs e)
    {
        txtFullName.Text = "";
        txtUser.Text = "";
        txtPass.Text = "";
        txtComfirmPass.Text = "";
        txtEmail.Text = "";
        Birthdate.Text = "";
        Capchar.IsValid = true;
    }
    protected void btRegister_Click(object sender, EventArgs e)
    {
        int year = Convert.ToInt32(Birthdate.Date.Year.ToString());
        int morth = Convert.ToInt32(Birthdate.Date.Month.ToString());
        int day = Convert.ToInt32(Birthdate.Date.Day.ToString());
        int today = Convert.ToInt32(DateTime.Now.Day.ToString());
        int toMonth = Convert.ToInt32(DateTime.Now.Month.ToString());
        int toYear = Convert.ToInt32(DateTime.Now.Year.ToString());
        if (year > toYear)
            validation(false);
        else
        {
            if (year < toYear)            
                validation(true);            

            if (year == toYear)
            {
                if (morth > toMonth)
                {
                    validation(false);
                }
                else
                {
                    if (morth < toMonth)                    
                        validation(true);                    

                    if (morth == toMonth)
                    {
                        if (day > today)
                        {
                            validation(false);
                        }
                        else
                        {
                            if (day < today)                            
                                validation(true);
                            
                            if (day == today)                            
                                validation(false);
                            
                        }
                    }
                }
            }

        }

    }
    protected void btOk_Click(object sender, EventArgs e)
    {
        Session["Username"] = txtFullName.Text;
        Response.Redirect("~/Default.aspx");
    }


    protected void Birthdate_ValueChanged(object sender, EventArgs e)
    {
        string morth = Birthdate.Date.Month.ToString();
        Response.Write(morth);
    }

}
